package online.inote.service;

import java.util.List;

import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import online.inote.common.base.ESService;
import online.inote.model.ArticleEntity;

/**
 * <p>
 * Desc: 文章Service
 * </p>
 *
 * @author Sui
 * @created: 2018年1月18日 下午10:08:57
 * @version 1.0
 */
@Service
public class ArticleService extends ESService<ArticleEntity, String> {

	public void initESData() {
		List<ArticleEntity> list = this.selectAll();
		
		if (!CollectionUtils.isEmpty(list)) {
			repository.saveAll(list);
		}
	}
	
	public void deleteAllESData() {
		List<ArticleEntity> list = this.selectAll();
		
		if (!CollectionUtils.isEmpty(list)) {
			repository.deleteAll(list);
		}
	}

	public void updateESMappingAndData() {
		this.deleteIndex();
		this.createIndex();
		this.putMapping();
		this.initESData();
	}
}